'use strict'

process.chdir(__dirname)

const cdpc = require('../index')

const cm = new cdpc({
  loadInfoFile: '--mem'
})

if (process.geteuid() !== 0) {
  console.log('请使用sudo 或切换到root用户执行')
  process.exit(0)
}

cm.cgroup.create('cdpcgrp', {
  cpu: [3500, 10000],
  io: {
    maj: 8,
    wbps: 1200,
    rbps: 20000,
    wiops: 5,
    riops: 5
  },
  pids: 'max',
  memory: 500000000,
  cpus: '%75='
}).then(() => {
  cm.runChilds([
    {
      name: 'nqueens',
      command: 'nqueens',
      cgroup: 'cdpcgrp',
      args: [ 36 ],
      restart: 'none',
      restartLimit: 0,
      autoRemove: true,
      user: 'wy',
      options: {
        stdio: ['ignore', 1, 2]
      },
      callback: (ch) => {
        console.log(ch.pid)
      }
    }
  
  ])  
})

cm.setStepSlice(10)
cm.setMaxStep(100, 105)
cm.monitorStart()

setTimeout(() => {
  cm.removeCgroup('cdpcgrp')
}, 2000)
